package logic

import (
	"context"
	"order/internal/svc"
	"order/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderLogic) CreateOrder(in *order.CreateOrderRequest) (*order.CreateOrderResponse, error) {
	// todo: add your logic here and delete this line

	//TODO:检查参数->检查用户->检查商品

	//TODO: 计算商品金额->检查商品库存

	//price, err := decimal.NewFromString("0.01")
	//if err != nil {
	//	return nil, err
	//}
	//
	//orderNum := uuid.NewString()
	//
	//orderInfo := model.Order{
	//	OrderNum:        orderNum,
	//	UserId:          in.UserId,
	//	SumPrice:        price.String(),
	//	OrderStatus:     model.OrderStateWaitPay,
	//	LogisticsStatus: 1,
	//}
	//err = model.Db.Create(&orderInfo).Error
	//if err != nil {
	//	return nil, err
	//}
	//
	//url, err := ali.Pay(price.String(), "用于支付++", orderNum)
	//if err != nil {
	//	log.Println(err)
	//	return &order.CreateOrderResponse{}, status.Error(codes.Internal, err.Error())
	//}
	//return &order.CreateOrderResponse{
	//	PayUrl: url,
	//}, nil
	return &order.CreateOrderResponse{}, nil
}
